package de.risk.game;

import java.util.ArrayList;
/**
 * Thread wird am Anfang des Spiels gestartet.
 * Am Ende des Spiels auf inaktiv gesetzt und aus der ArrayList deleted. Dann vom GC gekillt.
 * @author Oliver
 *
 */
public class RoundTimerThread implements Runnable{

	private int sec = 0;
	private static ArrayList<RoundTimerThread> roundThreads = new ArrayList<RoundTimerThread>();
	private static boolean isRunning;
	private int roundtime = 86400; //	86400 fuer 24 Stunden Runde
	
	
	
	



	@Override
	public void run() {
		isRunning = true;
		roundThreads.add(this);
		
		
		while (isRunning){
			
			
			if(sec == roundtime){
				Loop.doLoop();
				sec = 0;
			}
			
			
			sec++;
			waitSecs(1);			
			
		}
	}
	
	
	
	public static void endGame(){
		setRunning(false);
		roundThreads.clear();
	}
	
	
	
	public void waitSecs(int sec){
		try {
			wait(sec*1000);
		} catch (InterruptedException e) {
//			e.printStackTrace();
		}
	}
	
	

	
	public static ArrayList<RoundTimerThread> getRoundThreads() {
		return roundThreads;
	}



	public static void setRunning(boolean isRunning) {
		RoundTimerThread.isRunning = isRunning;
	}

	
	
	

}
